// routes/cards/findAllByGroup.js
const express = require('express');
const pool = require('../../config/pool'); // 使用连接池
const router = express.Router();
const isSuper = require('../../middleware/isSuper');

// 上架卡片
router.get('/:id', isSuper, (req, res) => {
    const { id } = req.params;
    // 校验id是否是数字
    if (!id || isNaN(id)) {
        return res.status(400).json({
            code: 0,
            message: 'id必须是数字',
            success: false
        });
    }
    const sql = 'UPDATE users SET is_admin = 1 WHERE id = ?';
    try {
        pool.query(sql, [id], (err, result) => {
            if (err) {
                res.status(500).json({
                    code: 0,
                    message: err.message,
                    success: false
                });
            }
            res.status(200).json({
                code: 1,
                message: '升级管理员成功',
                success: true
            });
        });
    } catch (error) {
        res.status(500).json({
            code: 0,
            message: error.message,
            success: false
        });
    }
});

module.exports = router;